FIX: uum 138143 button press points for stickcontrol and vector2 add functionality#2411
Conversation
…ld used for stick controls and Vector2. Test
…at a user declared as an interaction.
|
The diff contains approximately 325,668 tokens (~977,005 characters), which exceeds the maximum limit of 150,000 tokens. Please consider splitting this PR into smaller, focused changes. 🤖 Helpful? 👍/👎 |
…-stickcontrol-and-vector2-add-functionality # Conflicts: # Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlExtensions.cs
ekcoh
left a comment
There was a problem hiding this comment.
@Darren-Kelly-Unity Would it be possible to get rid of all the whitespace diffs on this PR? It would be much easier to review if this was corrected.
| /// </summary> | ||
| public float pressPointOrDefault => pressPoint > 0 ? pressPoint : s_GlobalDefaultButtonPressPoint; | ||
|
|
||
| float IActuationPressPoint.pressPoint => pressPoint; |
There was a problem hiding this comment.
To me it look odd that presspoint (new and previous is modelled on the control instead of on the interaction), what happens when two interactions with different press points bind to the same button?
There was a problem hiding this comment.
Confirmed this with AI but you can see in InputActionState.GetActuationPressThreshold() that:
There is an order, it is control-first for device semantics, interaction when the control does not override, then the default settings value.
AI Brief answer:
"Press threshold on the control models the physical control’s default; each binding’s interaction can still use its own press point when the control does not fix one, and separate bindings to the same button keep separate interaction state and thresholds unless the control’s own pressPoint is set, in which case that value wins for unified resolution."
There is also a longer text/ investigation done if you want to see that too?
…-stickcontrol-and-vector2-add-functionality
…-stickcontrol-and-vector2-add-functionality
… it was implicitly implemented.
ekcoh
left a comment
There was a problem hiding this comment.
Reviewed, I had quite a lot of questions and some remaining from last review so leaving this as comment-only for now.
| /// <summary> | ||
| /// Effective press threshold: <see cref="pressPoint"/> when set, otherwise the global default. | ||
| /// </summary> | ||
| float pressPointOrDefault { get; } |
There was a problem hiding this comment.
Why do we need two? Would it be better to have one, e.g. pressPoint that returns default if not having a layout-configured press threshold? Since both go through an interface anyway I wouldn't expect it to be an optimisation?
There was a problem hiding this comment.
This is just following the format that was already there for now, not sure about removing one as it was publicly available before.
| if (interactionState.totalTimeoutCompletionTimeRemaining > 0) | ||
| { | ||
| return (interactionState.totalTimeoutCompletionDone + timerCompletion * interactionState.timerDuration) / | ||
| return (interactionState.totalTimeoutCompletionDone + timerCompletion * interactionState.timerDuration) / |
There was a problem hiding this comment.
Looks like pure formatting diff and could be reverted
There was a problem hiding this comment.
I have left a few of the formatting changes in for now as they are correct. This one also looks ok I think?
| if (count == 0) | ||
| return null; | ||
| var start = bindingStateForInteractions->interactionStartIndex; | ||
| for (var i = 0; i < count; ++i) |
There was a problem hiding this comment.
Corner case: I am confused around this code, it looks like if there are multiple PressInteractions it will return the pressPoint of the first one? While this is probably OK, it might be good documenting it on PressInteraction or similar?
There was a problem hiding this comment.
Yes, It was already this way for buttonControl's previously. I have added documentation for this now.
| private float GetActuationPressThreshold(InputControl control, BindingState* bindingStatePtr) | ||
| { | ||
| var bindingForInteractions = GetBindingStateForInteractionParameters(bindingStatePtr); | ||
| var explicitPress = TryGetExplicitPressInteractionPressPoint(bindingForInteractions); |
There was a problem hiding this comment.
This cost is paid also when the first return is triggered. Did you compare any performance benchmark for this to rule out that these changes do not regress performance for various press configurations? Might be worthwhile to check since we have a combination here of virtual calls, fixed overhead evaluation, type checks etc.
| { | ||
| if (control is ButtonControl button) | ||
| buttonPressPoint = button.pressPointOrDefault; | ||
| if (control is IActuationPressPoint actuation) |
There was a problem hiding this comment.
Beware that this type check might be more expensive than the previous. Previously checking against a specific type, now checking for multiple types implementing interface. Its probably negligible but might we worth checking since hot-path.
There was a problem hiding this comment.
I added performance tests for this vs the legacy system, we can maybe chat about it in a call if that makes sense but I don't see much change here.
…ctor2Control.cs Co-authored-by: Håkan Sidenvall <hakan.sidenvall@unity3d.com>
…ctor2Control.cs Co-authored-by: Håkan Sidenvall <hakan.sidenvall@unity3d.com>
Purpose of this PR
Fixes UUM-138143 —
InputAction.IsPressed()/ in-progress style checks could fire at the wrong effective magnitude for Vector2 / stick bindings when developers setpressPointon the control or onPressInteraction, instead of honoring those thresholds consistently.Introduces
IActuationPressPoint, implements it onButtonControl,Vector2Control, and (viaVector2Control)StickControl, and threadspressPoint/pressPointOrDefaultthroughInputAction,InputActionState, andInputControlExtensionsso press-style polling matches the documented interaction defaults. AddsActuationPressPointTestsand refreshesRespondingToActions.md.Release Notes
InputAction.IsPressed()(and related press / in-progress behavior) for actions bound toVector2ControlandStickControlnow respects per-controlpressPointand bindingPressInteraction.pressPoint, aligning withButtonControland fixing incorrect early triggers when rewriting default interaction thresholds.Functional Testing status
ActuationPressPointTestsand updates inCoreTests_Actions/CoreTests_Controlscover press-point actuation paths.IsPressedbefore processed magnitude reaches the configured press threshold for vector / stick cases.Performance Testing Status
I have added performance testing for the hot path methods that Hakan flagged and I don't see any major issues when comparing. There is a slight increase in cost of performance of about 0.1ms for 1000 iterations on the GetActuationPressThreshold() method that was asked to be checked.
No new per-frame allocations identified in scope.
Overall Product Risks
Technical Risk: 2 — Touches
InputActionStateand widely used press APIs; edge cases around magnitude, deadzones, and interactions need regression confidence.Halo Effect: 2 — Any title using
IsPressed/WasPressedThisFrameon Vector2 / stick actions may see timing changes until bindings are tuned; behavior is intended to match documentedpressPointsemantics.Class diagram
Git range analyzed:
origin/develop...HEAD(4 commits).Mermaid class diagram (GitHub)
classDiagram direction TB class IActuationPressPoint { <<interface>> +pressPoint +pressPointOrDefault } class ButtonControl { +pressPoint +pressPointOrDefault } class Vector2Control { +pressPoint +pressPointOrDefault } class StickControl { } class InputAction { +IsPressed() +WasPressedThisFrame() +WasReleasedThisFrame() } class InputActionState { } class InputControlExtensions { <<static>> } IActuationPressPoint <|.. ButtonControl IActuationPressPoint <|.. Vector2Control Vector2Control <|-- StickControl InputAction --> InputActionState : uses InputControlExtensions ..> IActuationPressPoint : pressPointOrDefaultDocumentation Impact
Changes analyzed:
origin/develop...HEAD(4 commits).User-facing: New public
IActuationPressPoint;InputActionpress-helper remarks/behavior;ButtonControl,Vector2Control,StickControldocs aroundpressPoint;RespondingToActions.mdupdated for polling vspressPoint.Documentation updates in this PR
RespondingToActions.md— ClarifiesIsPressed/ frame helpers vs interactions andpressPoint; review wording and cross-refs after merge.Follow-up (optional)
IActuationPressPointcallout in a control reference page, add a short subsection and link from Responding to Actions.Jira (fetched via MCP): Bug, In Progress, TBD priority, assignee Darren Kelly, label Input-Actions. Ticket summary: InputAction.IsPressed() and IsInProgress() triggers on wrong values when rewriting the default values of Vector2 interactions.